package com.peanutplan.blog.model.vo;

import java.io.File;
import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ClassUtils;

import com.peanutplan.blog.constant.WebConst;
import com.peanutplan.blog.controller.admin.ArticleController;
import com.peanutplan.blog.utils.DefaultCover;

/**
 * @author 
 */
public class ContentVo implements Serializable {
    /**
     * post表主键
     */
    private Integer cid;

    /**
     * 内容标题
     */
    private String title;

    /**
     * 内容缩略名
     */
    private String slug;

    /**
     * 内容生成时的GMT unix时间戳
     */
    private Integer created;

    /**
     * 内容更改时的GMT unix时间戳
     */
    private Integer modified;

    /**
     * 内容所属用户id
     */
    private Integer authorId;

    /**
     * 内容类别
     */
    private String type;

    /**
     * 内容状态
     */
    private String status;

    /**
     * 标签列表
     */
    private String tags;
    
    private String[] tagList;

    /**
     * 分类列表
     */
    private String categories;

    /**
     * 点击次数
     */
    private Integer hits;

    /**
     * 内容所属评论数
     */
    private Integer commentsNum;

    /**
     * 是否允许评论
     */
    private Boolean allowComment;

    /**
     * 是否允许ping
     */
    private Boolean allowPing;

    /**
     * 允许出现在聚合中
     */
    private Boolean allowFeed;

    /**
     * 内容文字
     */
    private String content;
    
    /**
     * 纯文本内容
     */
    private String contentText;

    /**
     * 内容文字
     */
    private String remark;
    
    private String cover;
    
    private static final long serialVersionUID = 1L;

    public Integer getCid() {
        return cid;
    }

    public void setCid(Integer cid) {
        this.cid = cid;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    public Integer getCreated() {
        return created;
    }

    public void setCreated(Integer created) {
        this.created = created;
    }

    public Integer getModified() {
        return modified;
    }

    public void setModified(Integer modified) {
        this.modified = modified;
    }

    public Integer getAuthorId() {
        return authorId;
    }

    public void setAuthorId(Integer authorId) {
        this.authorId = authorId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getCategories() {
        return categories;
    }

    public void setCategories(String categories) {
        this.categories = categories;
    }

    public Integer getHits() {
        return hits;
    }

    public void setHits(Integer hits) {
        this.hits = hits;
    }

    public Integer getCommentsNum() {
        return commentsNum;
    }

    public void setCommentsNum(Integer commentsNum) {
        this.commentsNum = commentsNum;
    }

    public Boolean getAllowComment() {
        return allowComment;
    }

    public void setAllowComment(Boolean allowComment) {
        this.allowComment = allowComment;
    }

    public Boolean getAllowPing() {
        return allowPing;
    }

    public void setAllowPing(Boolean allowPing) {
        this.allowPing = allowPing;
    }

    public Boolean getAllowFeed() {
        return allowFeed;
    }

    public void setAllowFeed(Boolean allowFeed) {
        this.allowFeed = allowFeed;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getCover() {
		if(StringUtils.isNotBlank(this.cover) && this.cid!=null) {
			File img = null;
			String filePath = null;
			if(this.cover.startsWith("/profile/upload/")) {
				filePath = this.cover.replace("/profile/upload/", WebConst.defaultUploadBasedir);
			}
			if(this.cover.startsWith("/profile/")) {
				filePath = this.cover.replace("/profile/", WebConst.defaultProfile);
			}
			if(this.cover.startsWith("/cover/")) {
				filePath = this.cover.replace("/cover/", WebConst.defaultArticleCover);
			}
			if(this.cover.startsWith("/yqq/images/")) {
				String path = ClassUtils.getDefaultClassLoader().getResource("").getPath();
				filePath = path+"static"+this.cover;
			}
			try {
				img = new File(filePath);
				if(!img.exists()) {
					int random = ArticleController.getRandom(1, DefaultCover.DEFAULT_ARTICLE_COVER_MAP.size());
					this.cover = DefaultCover.DEFAULT_ARTICLE_COVER_MAP.get(new Integer(random));
				}
			} catch (Exception e) {
			}
		}
		if(StringUtils.isBlank(this.cover) && this.cid!=null) {
			int random = ArticleController.getRandom(1, DefaultCover.DEFAULT_ARTICLE_COVER_MAP.size());
			this.cover = DefaultCover.DEFAULT_ARTICLE_COVER_MAP.get(new Integer(random));
		}
		return cover;
	}

	public void setCover(String cover) {
		this.cover = cover;
	}

	public String getContentText() {
		return contentText;
	}

	public void setContentText(String contentText) {
		this.contentText = contentText;
	}

	public String[] getTagList() {
		if(StringUtils.isNotBlank(this.tags)) {
			this.tagList = this.tags.split(",");
		}
		return tagList;
	}

	public void setTagList(String[] tagList) {
		this.tagList = tagList;
	}
}